Support NodeJS by adding exports key to package.json#17
Support NodeJS by adding exports key to package.json#17kylewlacy wants to merge 5 commits intomhsdesign:mainfrom
exports key to package.json#17Conversation
|
hi ;) Thanks for digging into it and providing a pr :D So duplicating jit-browser-tailwindcss/build.js Lines 95 to 108 in 41437e8 and changing the target / creating a new output file in cjs should do https://esbuild.github.io/api/#format-commonjs? Also as written here https://esbuild.github.io/api/#main-fields |
|
At least for my use case, I'm trying to specifically use ES Modules with NodeJS, but I can update this PR to support CommonJS as well if you think that's beneficial. I found this SO answer that explains it pretty well: https://stackoverflow.com/a/75348391 I'll spend some time updating this PR when I have a chance. |
|
@mhsdesign Alright, done! I tweaked the esbuild script so it now builds a CommonJS file as well, then I tried testing it out briefly and it seemed like it worked. I also tweaked the ES Module export, since I realized TypeScript wasn't finding the module declaration unless some extra stuff was added to the |
Currently, trying to import
@mhsdesign/jit-browser/tailwindcssfrom a NodeJS project using ES Modules leads to a pretty cryptic error:I did some reading and found out this is because the
package.jsonfile doesn't list a NodeJS package entry point. Node either expects there to be a"main"field or"exports"field inpackage.json. Lots of packages have a"module"field, but Node doesn't use this (most bundlers support it though).This PR adds the
"exports"field topackage.json, which is roughly equivalent to the"module"field, but is used by NodeJS.